package com.esunny.resourcevisualization.manage;

import com.esunny.resourcevisualization.dao.ResourceTypeDao;
import com.esunny.resourcevisualization.dao.ResourceTypeEntityDao;
import com.esunny.resourcevisualization.dao.ResourceTypeEntityDataDao;
import com.esunny.resourcevisualization.dao.ResourceTypeFieldDao;
import com.esunny.resourcevisualization.domain.response.ReturnStructure;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @version 1.0.0.0
 * @ClassName ResourceManage
 * @Description 跨表-资源类别英文名操作
 * @Author baochencong
 * @Date 2020/9/28 10:40
 */
@Component
public class ResourceManage {

    @Resource
    private ResourceTypeDao resourceTypeDao;

    @Resource
    private ResourceTypeFieldDao resourceTypeFieldDao;

    @Resource
    private ResourceTypeEntityDao resourceTypeEntityDao;

    @Resource
    private ResourceTypeEntityDataDao resourceTypeEntityDataDao;

    private static Logger LOGGER = LoggerFactory.getLogger(ResourceManage.class);

    /**
     * 通过资源类别英文名删除该资源类别信息
     * @param name 资源类别英文名
     * @return 删除结果
     */
    public ReturnStructure deleteResourceTypeInfoByName(String name){
        try {
            resourceTypeEntityDataDao.deleteResourceTypeEntityDataByName(name);
            resourceTypeEntityDao.deleteResourceTypeEntityByName(name);
            resourceTypeFieldDao.deleteResourceTypeFieldByName(name);
            resourceTypeDao.deleteResourceTypeByName(name);
        }catch (Exception e){
            LOGGER.error("删除资源类别失败，错误为:");
            LOGGER.error(String.valueOf(e));
            return ReturnStructure.ERROR("删除资源类别失败",null);
        }
        return ReturnStructure.SUCCESS("删除该资源类别所有信息成功",null);
    }

}
